﻿using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Summary description for DecryptByAccount
/// </summary>
public class DecryptByAccount
{
    public DecryptByAccount()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static void DecByAccount(string AccountID)
    {
        using (HZ.Data.SQLHelper h = new HZ.Data.SQLHelper())
        {
            string sql = string.Format("SELECT * FROM BidPrice WHERE AccountID_TB = {0}", AccountID);
            System.Data.DataTable tb = h.ExecuteTable(sql);

            System.Text.StringBuilder sb = new System.Text.StringBuilder(8096);
            foreach (System.Data.DataRow item in tb.Rows)
            {
                if (item["EncryptedPrice"].ToString().Trim() == "" || item["EncryptedPrice"] == null)
                {
                    // sb.AppendLine(string.Format("UPDATE Project_BID SET SPPrice = NULL WHERE BIdid = {0}", item["bidid"].ToString()));
                }
                else
                {
                    sb.AppendLine(string.Format("UPDATE Project_BID SET SPPrice = {0}, SMPrice = Convert(float,{0}) / {2} WHERE BIdid = {1}", HZ.Encrypt.EncryptWrapper.DecrytPrice(null, item["EncryptedPrice"].ToString()), item["bidid"].ToString(), item["Factor"].ToString()));
                }
                if (sb.Length > 8000)
                {
                    h.ExecuteNonQuery(sb.ToString());
                    sb = new System.Text.StringBuilder(8096);
                }
            }

            if (sb.Length > 0)
            {
                h.ExecuteNonQuery(sb.ToString());
            }

        }

    }
}
